package com.bigpang.framework.cglibProxy;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @Author YongQiang
 * @Date 2021/7/13 15:03
 * @Version 1.0
 */
public class MyMethodInterceptor implements MethodInterceptor {

    /**
     *
     * @param o cglib生成的代理对象
     * @param method 被代理对象方法
     * @param objects 方法入参
     * @param methodProxy 代理方法
     * @return
     * @throws Throwable
     */
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

        System.out.println("插入前置通知");
        Object o1 = methodProxy.invokeSuper(o, objects);
        System.out.println("插入后置通知");
        return o1;
    }
}
